<template>
  <el-container class="height100 domain domainHeader">
    <el-header class="obpm-header-t" ref="top1">
      <admin_header :detail="detail" :desc="$t('enterprise_list')" :isCanExit="isCanExit" :showPartMenu="!showPartMenu"/>
    </el-header>
    <el-container class="allContainerHeight">
      <el-aside>
        <menulist @getActiveMenu="getActiveMenu" show="domain" v-if="!showPartMenu"/>
        <menulist @getActiveMenu="getActiveMenu" show="partMenu" v-else/>
      </el-aside>
      <el-main ref="tabCon" class="domainMain height100">
        <baseinfo ref='baseinfo' v-if="isShow.isBaseinfo && setup.domain.baseInfo"/>
        <department v-if="isShow.isDept && setup.domain.department" :key="DeptTimer"/>
        <user v-if="isShow.isUser && setup.domain.user"/>
        <appconfig v-if="isShow.isApp && setup.domain.appconfig"/>
        <weixin v-if="isShow.isWeixin && setup.domain.weixinConfig"/>
        <dingding v-if="isShow.isDingDing && setup.domain.dingdingConfig"/>
        <feishu v-if="isShow.isFeiShu && setup.domain.feishuConfig"/>
        <!-- <manager  v-if="isShow.isManager"/> -->
        <calendar v-if="isShow.isCalendar && setup.domain.calendar"/>
        <fieldextend v-if="isShow.isFieldextend && setup.domain.fieldextend" :key="fieldTimer"/>
        <userlog v-if="isShow.isUserlog && setup.domain.userlog"/>
        <flowstaterts v-if="isShow.isFlowstaters && setup.domain.flowstaterts"/>
        <emailconfig v-if="isShow.isEmailconfig && setup.domain.emailconfig"/>
        <timedtask v-if="isShow.isTimedTask && setup.domain.timedtask"/>
        <api_interface v-if="isShow.isAPIInterface && setup.domain.openApi"/>
        <cloud v-if="isShow.isCloud && setup.domain.cloudCapabilities"/>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import admin_header from "@/components/admin_header.vue";
import baseinfo from "@/components/baseinfo.vue";
import department from "@/components/department.vue";
import user from "@/components/user.vue";
import appconfig from "@/components/appconfig.vue";
import weixin from "@/components/weixin.vue";
import dingding from "@/components/dingding.vue";
import feishu from "@/components/feishu.vue";
import cloud from "@/components/cloud.vue";
import manager from "@/components/manager.vue";
import calendar from "@/components/calendar.vue";
import fieldextend from "@/components/fieldextend.vue";
import userlog from "@/components/userlog.vue";
import flowstaterts from "@/components/flowstaterts.vue";
import emailconfig from "@/components/emailconfig.vue";
import timedtask from "@/components/timedtask.vue";
import menulist from "@/components/menulist.vue"
import api_interface from "@/components/api_interface.vue"

export default {
  components: {
    admin_header,
    baseinfo,
    department,
    user,
    appconfig,
    weixin,
    dingding,
    feishu,
    cloud,
    manager,
    calendar,
    fieldextend,
    userlog,
    flowstaterts,
    emailconfig,
    timedtask,
    menulist,
    api_interface
  },

  created() {
    if(this.$store.state.currentUser && this.$store.state.currentUser.isOpenSecurity) {
      this.isOpen=true;
      if (this.$store.state.currentUser.type == 'admin') {
        this.isAdmin = true;//是否是系统管理员
        if (this.$store.state.currentUser.departments.length > 0 && this.$store.state.currentUser.domains.length > 0) {
          //部门及的系统管理员
          this.isAdminDept = true;
          this.activeName='Dept';
          this.isShow.isBaseinfo=false;
          this.isShow.isDept=true;

        }

      }else if(this.$store.state.currentUser.type == 'secret'){
        this.isSecret = true;//是否是安全保密员
        this.activeName='User';
        this.isShow.isBaseinfo=false;
        this.isShow.isUser=true;
      }
      else if(this.$store.state.currentUser.type == "examine"){
        this.isExamine = true;//是否是安全审计员
        this.activeName='Log';
        this.isShow.isBaseinfo=false;
        this.isShow.isUserlog=true;
      }
    }else{
      this.isOpen=false;
    }
    if(window.location.href.split("&")[1]){
      if(window.location.href.split("&")[1].indexOf("obpm")!=-1){
        this.isCanExit=false;
      }
    }
    // 域管理员
    if(sessionStorage.getItem('onlyDomainUser')){
      this.isCanExit = false;
    }else{
      this.isCanExit = true;
    }

    // 如果有from字段证明是从前台调整过来的(部门管理员)
    if(this.$route.query.from == 'systemManagement'){
      this.showPartMenu = true;
      this.isCanExit = false;
      this.getActiveMenu('Dept')
    }else{
      this.showPartMenu = false;
    }
    if(this.setup.domain){
      let domain = this.setup.domain;
      for(let key in domain){
        if(domain[key]){
          switch(key){
            case "baseInfo"://基本信息
              this.isShow.isBaseinfo = true
              break;
            case "department"://部门
            this.isShow.isDept = true
              break;
            case "user"://用户
            this.isShow.isUser = true
              break;
            case "appconfig"://软件
            this.isShow.isApp = true
              break;
            case "weixinConfig"://微信配置
            this.isShow.isWeixin = true
              break;
            case "dingdingConfig"://钉钉配置
            this.isShow.isDingDing = true
              break;
            case "feishuConfig"://飞书配置
            this.isShow.isFeiShu = true
              break;
            case "calendar"://工作日历
            this.isShow.isCalendar = true
              break;
            case "fieldextend"://字段扩展
            this.isShow.isFieldextend = true
              break;
            case "userlog"://操作日志
            this.isShow.isUserlog = true
              break;
            case "flowstaterts"://流程监控
            this.isShow.isFlowstaters = true
              break;
            case "emailconfig"://邮件设置
            this.isShow.isEmailconfig = true
              break;
            case "timedtask"://定时任务
            this.isShow.isTimedTask = true
              break;
            case "openApi"://Open API
            this.isShow.isAPIInterface = true
              break;
            case "cloudCapabilities"://云能力
            this.isShow.isCloud = true
              break;
          }
          break;
        }
      }
    }
    if(this.isSecret) { //安全保密员默认一开始选中用户列表
      this.getActiveMenu('User')
    }
    if(this.isExamine) { //安全审计员默认一开始选中操作日志
      this.getActiveMenu('Log')
    }
  },
  mounted(){
    
  },
  data() {
    return {
      staticPath: this.$api.getStaticPath(),
      setup: setup,
      activeName: "BasicInfo",
      isShow:{
        isBaseinfo:true,
        isDept:false,
        isUser:false,
        isApp:false,
        isWeixin:false,
        isDingDing:false,
        isFeiShu:false,
        isCloud:false,
        isManager:false,
        isCalendar:false,
        isFieldextend:false,
        isUserlog:false,
        isFlowstaters:false,
        isEmailconfig:false,
        isTimedTask:false,
        isAPIInterface: false
      },
      isCanExit:true,
      DeptTimer:'',
      UserTimer:'',
      fieldTimer:'',
      height:0,
      isOpen:false,//开关是否开启
      isAdmin:false,//是否是系统管理员
      isAdminDept:false,//标识是否是部门及的系统管理员
      isSecret:false,//是否是安全保密员
      isExamine:false,//是否是安全审计员
      detail: '', // 当前选中的是哪个页签
      showPartMenu: false, // 显示部分菜单
    };
  },

  methods: {
    resetisShow(){
      for(let i in this.isShow){
        this.isShow[i]=false;
      }
    },
    getActiveMenu(tab) {
      switch(tab){
        case "BasicInfo":
          this.resetisShow();
          this.detail = this.$t('baseInfo')
          this.isShow.isBaseinfo=true;
          break;
        case "Dept":
          this.resetisShow();
          this.isShow.isDept=true;
          this.detail =this.$t('department')
          this.DeptTimer=new Date().getTime();

          break;
        case "User":
          this.resetisShow();
          this.isShow.isUser=true;
          this.detail = this.$t('user')
          this.UserTimer=new Date().getTime();
          break;
        case "Apps":
          this.resetisShow();
          this.detail = this.$t('appconfig')
          this.isShow.isApp=true;
          break;
        case "WeixinConfig":
          this.resetisShow();
          this.detail =  this.$t('weixinConfig')
          this.isShow.isWeixin=true;
          break;
        case "DingDingConfig":
          this.resetisShow();
          this.detail = this.$t('dingdingConfig')
          this.isShow.isDingDing=true;
          break;
        case "FeiShuConfig":
          this.resetisShow();
          this.detail = this.$t('feishuConfig')
          this.isShow.isFeiShu=true;
          break;
        case "CloudConfig":
          this.resetisShow();
          this.detail = '云能力'
          this.isShow.isCloud=true;
          break;
        case "Adns":
          this.resetisShow();
          this.detail = this.$t('admin')
          this.isShow.isManager=true;
          break;
        case "WkCld":
          this.resetisShow();
          this.detail =  this.$t('calendar')
          this.isShow.isCalendar=true;
          break;
        case "UserFormExtends":
          this.resetisShow();
          this.detail =  this.$t('fieldextend')
          this.isShow.isFieldextend=true;
          this.fieldTimer=new Date().getTime();
          break;
        case "Log":
          this.resetisShow();
          this.detail = this.$t('userlog')
          this.isShow.isUserlog=true;
          break;
        case "FlowIntervention":
          this.resetisShow();
          this.detail = this.$t('flowstaterts')
          this.isShow.isFlowstaters=true;
          break;
        case "Email":
          this.resetisShow();
          this.detail = this.$t('emailconfig')
          this.isShow.isEmailconfig=true;
          break;
        case "TimedTask":
          this.resetisShow();
          this.detail = this.$t('timedtask')
          this.isShow.isTimedTask=true;
          break;
        case "APIInterface":
          this.resetisShow();
          this.detail = 'Open API'
          this.isShow.isAPIInterface=true;
          break;
      }
    }
  }
};
</script>

<style lang="scss">
.domain{
  .el-menu{
    border: none;
  }
}
</style>